package algame;

import static org.lwjgl.opengl.GL11.*;
import algame.Texture;
import algame.TextureLoader;

public class Font {

	private float[][] vertici = new float[5000][5];
	private int totvertici = 0;
	private float[] pos = new float[3];
	private float[] rot = new float[4];
	private float[] col = new float[3];
	private float[] sca = new float[3];
	private Texture tex_font;

	public void init(String texture, TextureLoader tl) {
		float div = 1 / 16;

		try {
			tex_font = tl.getTexture(texture);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}

		addVertex(0.0f ,0.2f ,0.0f ,div ,0.0f);
		addVertex(0.0f ,0.0f ,0.0f ,0.0f ,0.0f);
		addVertex(0.0f ,0.0f ,0.2f ,0.0f ,div);
		addVertex(0.0f ,0.2f ,0.2f ,div ,div);

	}

	public void addVertex(float vx,float vy,float vz,float tx,float ty) {
		vertici[totvertici][0] = vx;
		vertici[totvertici][1] = vy;
		vertici[totvertici][2] = vz;
		vertici[totvertici][3] = tx;
		vertici[totvertici][4] = ty;
		totvertici++;
	}

	public void scol(float vr, float vg, float vb) {
		col[0] = vr;
		col[1] = vg;
		col[2] = vb;
	}

	public void spos(float vx, float vy, float vz) {
		pos[0] = vx;
		pos[1] = vy;
		pos[2] = vz;
	}

	public void srot(float value, float vx, float vy, float vz) {
		rot[0] = value;
		rot[1] = vx;
		rot[2] = vy;
		rot[3] = vz;
	}

	public void ssca(float sx, float sy, float sz) {
		sca[0] = sx;
		sca[1] = sy;
		sca[2] = sz;
	}

	public void render(String text) {

		glEnable(GL_TEXTURE_2D);

		tex_font.bind();

		glPushMatrix();

		glScalef(sca[0],sca[1],sca[2]);
		glRotatef(rot[0], rot[1], rot[2], rot[3]);
		glTranslatef(pos[0], pos[1], pos[2]);

		glColor3f(col[0],col[1],col[2]);

		glBegin(GL_TRIANGLES);

		for(int i = 0; i < totvertici; i++) {
			glTexCoord2f(vertici[i][3], vertici[i][4]);
			glVertex3f(vertici[i][0], vertici[i][1], vertici[i][2]);
		}

		glEnd();

		glPopMatrix();
	}

}
